{include file="public/head" /}
  
  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a><cite>后台管理</cite></a>
        <a><cite>物业管理系统</cite></a>
        <a><cite>微信管理</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body">
      <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so"  method="get" action="{:url('userList')}">
          <!-- <input type="text" name="owner_name"  placeholder="业主姓名" autocomplete="off" class="layui-input" value=""> -->
          <div class="layui-input-inline">
            <select name="community_id" lay-filter="community_id" id="community_id">
              <option value="">所属小区</option>
              {foreach $communitylist as $name}
              <option value="{$name.id}" {if isset($community_id)}{if $community_id == $name.id}selected{/if}{/if}>{$name.name}</option>
              {/foreach}
            </select>
          </div>

          <input class="layui-input" placeholder="姓名" name="name1" value="{if isset($name1)}{$name1}{/if}">

          <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
      </div>
      <xblock>
        <!--<button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>-->
        <button class="layui-btn " onclick="x_admin_show('添加','{:url('userAdd')}',600,600)"><i class="layui-icon"></i>添加</button>
        <button class="layui-btn layui-btn-danger" onclick="x_admin_show('批量导入','{:url('userExcel')}',600,400)"><i class="layui-icon"></i>批量导入</button>
        <button class="layui-btn" onclick="userExportExcel('{$export}')"><i class="layui-icon"></i>批量导出</button>
        <span class="x-right" style="line-height:40px">共有数据： {$number}条</span>
      </xblock>
      <table class="layui-table" id="table">
        <thead  style="text-align:center;">
          <tr>
            <th style="width: 4%;text-align:center;">
                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th style="text-align:center;">小区名称</th>
            <th style="text-align:center;">组团</th>
            <th style="text-align:center;">楼栋</th>
            <th style="text-align:center;">单元</th>
            <th style="text-align:center;">房号</th>
            <th style="text-align:center;">楼层号</th>
            <th style="text-align:center;">姓名</th>
            <th style="text-align:center;">手机号</th>
            <th style="text-align:center;">绑定码</th>
            <th style="text-align:center;">openid</th>


            <th style="text-align:center;">添加时间</th>
			
            <th style="text-align:center;">操作</th>
            <!-- 8 -->
          </tr>
        </thead>
        <tbody style="text-align:center;">
          {foreach $list as $val}
          <tr>
            <td>
                <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='{$val.id}'><i class="layui-icon">&#xe605;</i></div>
            </td>
            <td>{$val.community_name}</td>
            <td>{$val.group}</td>
            <td>{$val.building}幢</td>
            <td>{$val.unit}单元</td>
            <td>{$val.room}室</td>
            <td>{$val.wiegand}</td>
            <td>{$val.name}</td>
            <td>{$val.phone}</td>
            <td>{$val.bind_code}</td>
            <td>{$val.openid}</td>
            <td style="font-size:10px">{$val.create_time|date="Y-m-d H:i:s",###}</td>
            <td class="td-manage">
              <button type="button" class="layui-btn  layui-btn-sm layui-btn-zaozao" onclick="x_admin_show('编辑','{:url(\'admin/wxuser/deviceauth\')}?id={$val.id}',600,600)" style="font-size:8px">授权</button>

              <button type="button" class="layui-btn-zaozao" onclick="userDel('{$val.id}')" style="background-color: #ff0000">删除</button>
            </td>
          </tr>
          {/foreach}
        </tbody>
      </table>
      <div class="page">
        <div id="page">
            {$userlist->render()}
        </div>
      </div>

    </div>
    <script>

      layui.use('laydate', function(){
        var laydate = layui.laydate;
        
        //执行一个laydate实例
        laydate.render({
          elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
          elem: '#end' //指定元素
        });
      });
      //批量删除
      function delAll () {
        var datas = $('#table tbody td .layui-form-checked')
        var ids = []
        datas.each(function(index, element){
          var id = $(this).data('id')
          ids.push(id)
        })

        var str = ids.join(',');
        var count = ids.length
        layer.confirm('你确定要删除这'+ count + '项吗', function(){
          $.post('{:url("userDelAll")}', { id: str}, function(r){
            if (r.info) {
              layer.msg(r.info)
            }else{
              location.reload()
            }
          })
        })
      }

      function userDel(id){
          if(confirm('确定要删除吗?'))
          {
              var url = "{:url('userDel')}?id=" + id;
              window.location.href=url;
              console.log(url)
              //$('#' + doc).attr('href', url)
          }
          return false;
      }
      //批量导出
      function userExportExcel(exportid){
        var datas = $('#table tbody td .layui-form-checked')
        var ids = []
        datas.each(function(index, element){
          var id = $(this).data('id')
          ids.push(id)
        })

        var str = ids.join(',');
        var count = ids.length
        var url = "{:url('userExportExcel')}?id=" + str +'&export=' + exportid
        layer.open({
          type: 2,
          title: '批量导出',
          shadeClose: true,
          shade: 0.8,
          area: ['80%', '95%'],
          content: url //iframe的url
        }); 
      }
      
    </script>
    
    <script>
        layui.use(['form'], function() {
            var form = layui.form
            form.on('select(community_id)', function(f){
                var url = "{:url('fetchdata')}"
                $.post(url, {community_id: f.value, type: 1}, function(data) {
                    $('#group').html("")
                    var option = "<option value=''>所有组团</option>"
                    $('#group').append(option)
                    for (var i = 0; i < data.length; i++) {
                    option = "<option value='" + data[i] + "'>" + data[i] + "</option>"
                    $('#group').append(option)
                    }
                    
                    form.render('select')
                })
                
                $('#community_id').data('community_id', f.value)
            })

            form.on('select(group)', function(f){
                var data_community = $('#community_id').data('community_id')
                var get_community = "<?php if (isset($community_id)) { echo $community_id;}?>"
                var community_id = typeof data_community === 'undefined' ? get_community : data_community
                var url = "{:url('fetchdata')}"
                $.post(url, {community_id: community_id, group: f.value, type: 2}, function(data) {
                    $('#building').html("")
                    var option = "<option value=''>所有楼栋</option>"
                    $('#building').append(option)
                    for (var i = 0; i < data.length; i++) {
                        option = "<option value='" + data[i] + "'>" + data[i] + "幢</option>"
                        $('#building').append(option)
                    }
                    $('#group').data('group', f.value)
                    form.render('select')
                })
            })
    
            form.on('select(building)', function(f){
                var data_community = $('#community_id').data('community_id')
                var get_community = "<?php if (isset($community_id)) { echo $community_id;}?>"
                var community_id = typeof data_community === 'undefined' ? get_community : data_community

                var data_group = $('#group').data('group')
                var get_group = "<?php if (isset($group)) { echo $group;}?>"
                var group = typeof data_group === 'undefined' ? get_group : data_group

                var url = "{:url('fetchdata')}"
                $.post(url, {building: f.value, community_id: community_id, group: group, type: 3}, function(data) {
                $('#unit').html("")
                var option = "<option value=''>所有单元</option>"
                $('#unit').append(option)
                for (var i = 0; i < data.length; i++) {
                    option = "<option value='" + data[i] + "'>" + data[i] + "单元</option>"
                    $('#unit').append(option)
                }
                $('#building').data('building', f.value)
                form.render('select')
                })
            })
    
            form.on('select(unit)', function(f){
                var data_community = $('#community_id').data('community_id')
                var get_community = "<?php if (isset($community_id)) { echo $community_id;}?>"
                var community_id = typeof data_community === 'undefined' ? get_community : data_community

                var data_group = $('#group').data('group')
                var get_group = "<?php if (isset($group)) { echo $group;}?>"
                var group = typeof data_group === 'undefined' ? get_group : data_group

                var data_building = $('#building').data('building')
                var get_building = "<?php if (isset($building)) { echo $building;}?>"
                var building = typeof data_building === 'undefined' ? get_building : data_building
        
                var url = "{:url('fetchdata')}"
                $.post(url, {unit: f.value, community_id: community_id, group: group, building: building, type: 4}, function(data) {
                $('#room').html("")
                var option = "<option value=''>所有房间</option>"
                $('#room').append(option)
                for (var i = 0; i < data.length; i++) {
                    option = "<option value='" + data[i] + "'>" + data[i] + "室</option>"
                    $('#room').append(option)
                }
                $('#unit').data('unit', f.value)
                form.render('select')
                })
            })
    
        })
    </script>

    <script>var _hmt = _hmt || []; (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();
    </script>

  </body>

</html>